package com.autoEcole.service;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.autoEcole.dao.ExaminateurDAO;
import com.autoEcole.exception.ApplicationException;
import com.autoEcole.exception.DAOException;
import com.autoEcole.model.Examinateur;

public class ExaminateurService {
	
	private ExaminateurDAO examinateurDAO;
	/**
	 * ExaminateurService
	 */
	private static ExaminateurService examinateurService;
	
	/**
	 * Constructor
	 */
	private ExaminateurService() {
		super();
	}

	/**
	 * Returns the ExaminateurService instance (Design Pattern : Singleton)
	 * 
	 * @return ExaminateurService
	 */
	public static synchronized ExaminateurService getInstance() {
		if (examinateurService == null)
			examinateurService = new ExaminateurService();
		return examinateurService;
	}

	public ExaminateurDAO getExaminateurDAO() {
		return examinateurDAO;
	}

	public void setExaminateurDAO(ExaminateurDAO examinateurDAO) {
		this.examinateurDAO = examinateurDAO;
	}

	public int create(Examinateur examinateur) throws ApplicationException {
		try {
			return examinateurDAO.create(examinateur);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * 
	 */
	public void update(Examinateur examinateur) throws ApplicationException {
		try {
			examinateurDAO.update(examinateur);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * retourne l'element si il existe ou null
	 */
	public Examinateur findById(int id) throws ApplicationException {
		try {
			return examinateurDAO.findById(id);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * @throws ParseException 
	 * 
	 */
	public List<Examinateur> findAll() throws ApplicationException, ParseException {
		try {
			return examinateurDAO.findAll();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
	
	/**
	 * 
	 */
	public Map<Integer , Examinateur> findAllMap() throws ApplicationException {
		try {
			return examinateurDAO.findAllMap();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}
	
	/**
	 * 
	 */	
	public void delete(int examinateurId) throws ApplicationException {
		try {
			examinateurDAO.delete(examinateurId);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
}
